package stc.skymobi.unit.cmds;

import java.util.Map;

import bsh.CallStack;
import bsh.Interpreter;

public class getSourceInfo extends UnitCmds {
    public static void invoke( 
    		final Interpreter env, 
    		final CallStack callstack, 
    		final String pattern ) throws Exception {
		final Map<String, Map<String, String>> infos = getUnitAdmin().getSourceInfo(pattern);
		
		env.eval("print( \"source pattern (" + pattern +") infos:\");");
		
		if ( null != infos ) {
			for ( Map.Entry<String, Map<String, String>> entry : infos.entrySet()) {
				env.eval("print( \"\\t source:" + entry.getKey() + "\");");
				printOneSourceInfo(env, entry.getValue());
			}
		}
    }
    
    private static void printOneSourceInfo (
    		final Interpreter env, 
    		final Map<String, String> placeholders ) throws Exception {
		for ( Map.Entry<String, String> entry : placeholders.entrySet()) {
			env.eval("print( \"\\t\\t" + entry.getKey() + "=" + entry.getValue() +"\");");
		}
    }
}
